package com.stylefeng.guns.modular.clm.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ClmResource;
import com.stylefeng.guns.modular.clm.service.IClmResourceService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-04-04 16:54:00
 */
@Controller
@RequestMapping("/clmResource")
public class ClmResourceController extends BaseController {

    private String PREFIX = "/clm/clmResource/";

    @Autowired
    private IClmResourceService clmResourceService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "clmResource.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/clmResource_add")
    public String clmResourceAdd() {
        return PREFIX + "clmResource_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/clmResource_update/{clmResourceId}")
    public String clmResourceUpdate(@PathVariable Integer clmResourceId, Model model) {
        ClmResource clmResource = clmResourceService.selectById(clmResourceId);
        model.addAttribute("item",clmResource);
        LogObjectHolder.me().set(clmResource);
        return PREFIX + "clmResource_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return clmResourceService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ClmResource clmResource) {
        clmResourceService.insert(clmResource);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer clmResourceId) {
        clmResourceService.deleteById(clmResourceId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ClmResource clmResource) {
        clmResourceService.updateById(clmResource);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{clmResourceId}")
    @ResponseBody
    public Object detail(@PathVariable("clmResourceId") Integer clmResourceId) {
        return clmResourceService.selectById(clmResourceId);
    }
}
